home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / simple6a / module1.bas < prev    next >
BASIC Source File  |  1999-09-22  |  2KB  |  62 lines

  1. Attribute VB_Name = "Module1"
  2. 'Declare the Public variables needed for the game to work
  3. Public Sqa As Integer, Sqb As Integer, X As Integer, Y As Integer
  4.  
  5. Sub HideAll()
  6.     Dim I As Integer
  7. 'Hide all pieces, if they aren't already hidden
  8.     For I = 0 To 80
  9.         If Form1.Picture1(I).Visible <> False Then Form1.Picture1(I).Visible = False
  10.     Next I
  11. End Sub
  12.  
  13. Sub Start()
  14.     Dim I As Integer, J As Integer, A As Integer
  15. 'Calculate the piece dimensions. X is the piece's Width
  16. 'and Y is the piece Height
  17.     X = Form1.Picture2.ScaleWidth / Sqa
  18.     Y = Form1.Picture2.ScaleHeight / Sqb
  19. 'Set the mouse pointer to a hour glass
  20.     Screen.MousePointer = 11
  21. 'Clear the form, disable the shuffle option, clear the
  22. 'PictureBox container and make it invisible
  23.     'Form1.Cls
  24.     Form1.mnuShuffle.Enabled = True
  25.     Form1.Picture2.Cls
  26.     Form1.Picture2.Visible = False
  27. 'Now start creating each piece of the puzzle
  28.     For I = 0 To Sqa - 1
  29.         For J = 0 To Sqb - 1
  30.             A = I * Sqb + J
  31. 'Save its correct position in the picture's Tag property
  32.             Form1.Picture1(A).Tag = Format(I * X, "@@@@@@@") & Format(J * Y, "@@@@@@@")
  33. 'Set its dimensions
  34.             Form1.Picture1(A).Width = X
  35.             Form1.Picture1(A).Height = Y
  36. 'Paint the correct image on the piece and make it visible
  37.             Form1.Picture1(A).PaintPicture Form2.Image1.Picture, 0, 0, X, Y, I * Form2.Image1.Width / Sqa, J * Form2.Image1.Height / Sqb, Form2.Image1.Width / Sqa, Form2.Image1.Height / Sqb
  38.             Form1.Picture1(A).Visible = True
  39.         Next J
  40.     Next I
  41. 'Make the PictureBox container visible and set the mouse
  42. 'pointer to the default pointer
  43.     Form1.Picture2.Visible = True
  44.     Screen.MousePointer = 0
  45. 'Shuffle the pieces
  46.     Shuffle
  47. End Sub
  48.  
  49. Sub Shuffle()
  50.     Dim I As Integer, J As Integer
  51. 'Move the pieces 150 times so that they are correctly
  52. 'shuffled
  53.     For I = 1 To 150
  54.         DoEvents
  55. 'Select a random piece
  56.         J = Int(Rnd * Sqb * Sqa)
  57. 'Position it in a random position
  58.         Form1.Picture1(J).Left = Int(Rnd * Form1.ScaleWidth - X / 2)
  59.         Form1.Picture1(J).Top = Int(Rnd * Form1.ScaleHeight - Y / 2)
  60.     Next I
  61. End Sub
  62.